<?php $this->headStyle()->captureStart()?>
    #content td { padding:5px}
    #content table { border:1px #aaa solid; padding:5px; width:100%}
    #content th {font-weight:bold;}

<?php $this->headStyle()->captureEnd()?>
<?php $this->JQuery()->javascriptCaptureStart()?>
	$j(document).ready(function() {
	
		$j('#company_form').submit(function(e) {
                    if ($j('#company_name').attr('value') == ''){
                        $j('#company_name').css('border', '1px solid red');
                        return false;
                    } else {
                        $j('#company_name').css('border', 'none');
                    }

                    if ($j('#contact_phone').attr('value') != ''){

                        if ($j('#contact_phone').attr('value').match(/^\d+$/) == null){
                            $j('#contact_phone').css('border', '1px solid red');
                            return false;
                        } else {
                            $j('#contact_phone').css('border', 'none');
                        }
                    }
                   
                    if ($j('#business_category').attr('value') == ''){
                        $j('#business_category').css('border', '1px solid red');
                        return false;
                    } else {
                        $j('#business_category').css('border', 'none');
                    }
		});
		
		$j('#company_name').blur(function() {
			if ($j('#company_name').attr('value') != ''){
				
				$j.post(
						'/default/index/find-company',
						{data:$j('#company_name').attr('value')},
						function (data) {
							if(data.res == 'not') {
								$j('#company_name').css('border', '1px solid yellow');
								return false;
							} else {
								$j('#company_name').css('border', 'none');
							}
							
						}
					);
					return false;
				}
		});
	
	});
<?php $this->JQuery()->javascriptCaptureEnd()?>

<h2>Upgrade Form</h2>
<h2><?php echo $this->user->un?></h2>
<br><br>
<form id="company_form" method="post">
Company Name: <input type="text" id="company_name" name="company_name" value=""><br/>
Phone: <input type="text" id="contact_phone" name="contact_phone" value=""><br/>
Business Category: <?php
    $bd = Model_Category::one(array('id' => 'mc52'));
    $id = $bd->_id;

    $locs = Model_Category::all(array('_id' => array('$ne' => new MongoId($id)),  'path' => new MongoId($id), 'status' => Model_Category::STATUS_ACTIVE))->sort(array('pos' => 1));
    $parent = '';
    $locations = array(); ?>
    <select name="business_category" id="business_category">
            <option value=""><?php echo $this->t('Select')?></option>
    <?php foreach($locs as $k => $loc):?>
        <?php if (count($loc->path) == 2):?>
            <option value="<?php echo $loc->_id?>"><?php echo $loc->name?></option>
        <?php endif;?>
    <?php endforeach;?>
    </select><br/>
District: <?php
    $locs = Model_Location::all()->sort(array('path' => 1));
    $parent = '';
    $locations=array();
    foreach($locs as $k => $loc) {
            if (count($loc->path) == 1) {
                    $parent = $loc->name;
                    $locations[$loc->name] = array();
            } else {
                    $tmp    = !empty($locations[(string) $parent]) ? $locations[(string) $parent] : array();
                    $tmp[$k]         = (string) $loc->name;
                    $locations[(string) $parent] = $tmp;
            }
    } ?>

    <select name="location" id="location">
            <option value=""><?php echo $this->t('Select')?></option>
    <?php foreach($locations as $k => $locs):?>
            <optgroup label="<?php echo $k?>">
            <?php foreach($locs as $j => $loc):?>
                    <option value="<?php echo $j?>"><?php echo $loc?></option>
            <?php endforeach;?>
            </optgroup>
    <?php endforeach;?>
    </select><br/>
Mailing Address: <textarea name="mailing_address" id="mailing_address"></textarea><br/>
Website: <input type="text" name="website" id="website" value="http://" /><br/>				
First Name: <input type="text" value="" id="contact_firstname" name="contact_firstname"><br/>
Last Name: <input type="text" value="" id="contact_lastname" name="contact_lastname"><br/>
Department: <input type="text" name="contact_department" id="contact_department" value=""><br/>
Job Title: <input type="text" name="contact_job" id="contact_job" value=""><br/>
Mobile Phone: <input type="text" name="phone" id="phone" value=""><br/>
Email Address: <input type="text" name="contact_email" id="contact_email" value=""><br/>
About Us: <textarea name="about" id="about"></textarea><br/>				
				
<button>Upgrade</button>
</form>